package com.carsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.carsystem.entity.Login;
import com.carsystem.mapper.LoginMapper;
import com.carsystem.service.LoginService;
import com.carsystem.utils.Result;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.Service;

import javax.annotation.Resource;

@Service
public class LoginServiceImpl extends ServiceImpl<LoginMapper, Login> implements LoginService {

    @Resource
    private LoginMapper loginMapper;

    @Override
    public Result addAccount(Login login) {
        int insert = loginMapper.insert(login);
        if (insert==1){
            return new Result(true, "注册成功");
        }
        return new Result(true,"注册失败");
    }

    @Override
    public Result selectAccount(String username, String password) {
        QueryWrapper<Login> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username).eq("password",password);
        Login login = loginMapper.selectOne(queryWrapper);
        if (login!=null){
            return new Result(true,"登录成功",login);
        }
        return new Result(false,"登录失败");
    }

    @Override
    public Login selectByUsername(String username) {
        QueryWrapper<Login> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",username);
        return loginMapper.selectOne(queryWrapper);
    }
}
